package lock;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @author mubei
 * @date 2021/11/20
 * @description
 */
@SuppressWarnings("ALL")
public class TestLock implements Runnable {

    int tickCount = 10;
    private final ReentrantLock lock = new ReentrantLock();
    @Override
    public void run() {
        while(true){
            try{
                lock.lock();
                if(tickCount > 0 ){
                    Thread.sleep(100);
                    System.out.println(tickCount--);
                }else{
                    break;
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            } finally{
                lock.unlock();
            }

        }
    }

    public static void main(String[] args) {
        TestLock testLock = new TestLock();
        new Thread(testLock).start();
        new Thread(testLock).start();
        new Thread(testLock).start();
    }
}
